package com.ruoyi.project.tickets.controller;

import java.util.List;

import com.ruoyi.project.tickets.domain.dto.OutStockDto;
import com.ruoyi.project.tickets.domain.query.OutStockQuery;
import com.ruoyi.project.tickets.domain.vo.OutStockVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.tickets.domain.OutStock;
import com.ruoyi.project.tickets.service.IOutStockService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 出库记录Controller
 *
 * @author 孙山伟
 * @date 2023-07-01
 */
@RestController
@RequestMapping("/tickets/outstock")
public class OutStockController extends BaseController
{
    @Autowired
    private IOutStockService outStockService;

    /**
     * 查询出库记录列表
     */
    @PreAuthorize("@ss.hasPermi('tickets:outstock:list')")
    @GetMapping("/list")
    public TableDataInfo list(OutStockQuery query)
    {
        startPage();
        List<OutStockVo> list = outStockService.selectOutStockList(query);
        return getDataTable(list);
    }

    /**
     * 导出出库记录列表
     */
    @PreAuthorize("@ss.hasPermi('tickets:outstock:export')")
    @Log(title = "出库记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OutStockQuery outStock)
    {
        List<OutStockVo> list = outStockService.selectOutStockList(outStock);
        ExcelUtil<OutStockVo> util = new ExcelUtil<OutStockVo>(OutStockVo.class);
        return util.exportExcel(list, "outstock");
    }

    /**
     * 获取出库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('tickets:outstock:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(outStockService.selectOutStockById(id));
    }

    /**
     * 新增出库记录
     */
    @PreAuthorize("@ss.hasPermi('tickets:outstock:add')")
    @Log(title = "出库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(List<OutStockDto>  dtoList)
    {
        return toAjax(outStockService.insertOutStock(dtoList));
    }

    /**
     * 修改出库记录
     */
    @PreAuthorize("@ss.hasPermi('tickets:outstock:edit')")
    @Log(title = "出库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OutStock outStock)
    {
        return toAjax(outStockService.updateOutStock(outStock));
    }

    /**
     * 删除出库记录
     */
    @PreAuthorize("@ss.hasPermi('tickets:outstock:remove')")
    @Log(title = "出库记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(outStockService.deleteOutStockByIds(ids));
    }
}
